<template>
  <!--开票记录-->
  <div>
    <!--全部-->
    <div>
      <span style="padding: 0 10px"><i class="font-14 el-icon-s-open"></i></span>
     <!-- <el-select v-model="allValue" value-key="id" @change="findInvoice(allValue)" placeholder="全部数据" style="width: 120px">
        <el-option-group v-for="group in allOptions" :key="group.label" :label="group.label">
          <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item">
          </el-option>
        </el-option-group>
      </el-select>
      <span style="padding: 0 10px 0 30px"><i class="fn el-icon-message-solid"></i></span>
      <el-input  v-model="content" clearable placeholder="请输入内容" style="width: 150px"></el-input>
      <el-select v-model="jhValue" placeholder="开票日期" style="width: 140px">
        <el-option v-for="item in jhOptions" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <el-button @click="findClientOrDate" icon="el-icon-search" size="small" circle></el-button>-->
      <el-select v-model="filterValue" @change="initData(currPage, pageSize,filterValue,vagueValue,content)" placeholder="全部数据" style="width: 120px">
        <el-option-group v-for="group in filterOptions" :key="group.label" :label="group.label">
          <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item">
          </el-option>
        </el-option-group>
      </el-select>
      <span style="padding: 0 10px 0 30px"><i class="fn el-icon-message-solid"></i></span>
      <el-input v-model="content" clearable placeholder="请输入内容" clearable style="width: 150px"></el-input>
      <el-select v-model="vagueValue" @change="initData(currPage, pageSize,filterValue,vagueValue,content)" placeholder="客户名称" style="width: 120px">
        <el-option v-for="item in vagueOptions" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <el-button @click="initData(currPage, pageSize,filterValue,vagueValue,content)" icon="el-icon-search" size="small" circle></el-button>
    </div>
    <!--新建-->
    <div style="margin-top: 15px">
      <div class="col-sm-开票记录 text-left" style="margin-bottom: 20px">
        <span set-lan="html:开票记录">开票记录</span>
        <small class="text-muted font-13">共{{totalSize}}条</small>
      </div>
      <div class="col-sm-6 text-right">
        <el-button type="text" @click="dialogFormVisible = true">
          <el-button size="small" icon="el-icon-circle-plus-outline">新建</el-button>
        </el-button>
      </div>
      <!--开票记录dialog-->
        <el-dialog title="开票记录" :visible.sync="dialogFormVisible" width="60%" @open="openDialog" @close='closeDialog' style="color: #333333"  >
          <el-form :model="RecordInvoice" label-width="100px" :rules="rules" ref="rei">
            <hr style="margin-bottom: 15px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="对应客户:" style="width: 830px" prop="customerByCustomerId.customerName">
                  <el-input :disabled="true" v-model="RecordInvoice.customerByCustomerId.customerName"></el-input>
                </el-form-item>
                <div class="form-inline" v-show="isCustomer">
                  <el-input v-model="customerValue" clearable @input="findCustomer" size="medium" placeholder="拼音.字母.关键字" style="width: 150px"></el-input>
                  <el-button @click="findCustomer" size="medium" icon="el-icon-search"></el-button>
                  <el-popover placement="top" v-model="visible">
                    <div style="margin-bottom: 10px">
                      <span>查询条件:{{customerValue}}</span>
                      <span @click="closeEmp" class="cursor" style="float: right"><i class="el-icon-error"></i></span>
                    </div>
                    <ul class="cu-ul" v-if="customerList2 !== ''">
                      <li @click="choiceCustomer2(item)" v-for="item in customerList2">{{item.customerName}}</li>
                    </ul>
                    <div style="margin: 5px 0;text-align: center" v-if="customerList2 == ''">
                      <i class="el-icon-warning-outline"/>没有符合条件的客户！
                    </div>
                  </el-popover>
                  <el-tooltip class="item" effect="dark" content="浏览选择客户" placement="bottom">
                    <el-button @click="innerVisible(cusCurrPage,cusPageSize)" size="medium" icon="el-icon-s-operation"></el-button>
                  </el-tooltip>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="合同订单:" prop="contractByContractId">
                  <!--key绑定主键，要和select的value-key属性对应，引用字段名要一致，label用于显示内容，value值用来包含对象，用来提交-->
                  <el-select v-model="RecordInvoice.contractByContractId" value-key="contractId" placeholder="未选" style="width: 730px">
                    <el-option v-for="item in contractList" :key="item.contractId" :label="item.contractTheme" :value="item">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="开票内容:" style="width: 395px">
                  <el-input v-model="RecordInvoice.invoicerecordContent"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="票据类型:">
                  <el-select v-model="RecordInvoice.invoicerecordType" placeholder="未选"  style="width: 290px">
                    <el-option v-for="item in invoicetypeOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="票据金额:" style="width: 395px" prop="invoicerecordAmount">
                  <el-input v-model="RecordInvoice.invoicerecordAmount"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="发票号码:" style="width: 370px" prop="invoicerecordNo">
                  <el-input style="width: 292px" v-model="RecordInvoice.invoicerecordNo">
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="开票日期:" style="width: 395px" prop="invoicerecordDate">
                  <el-date-picker  type="date" placeholder="选择日期" style="width: 296px" v-model="RecordInvoice.invoicerecordDate"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="期次:" prop="invoicerecordPeriods">
                  <el-select v-model="RecordInvoice.invoicerecordPeriods" placeholder="未选"  style="width: 290px">
                    <el-option v-for="item in periods" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="经手人:" style="width: 830px">
                  <el-input v-model="RecordInvoice.invoicerecordHandlers">
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="是否回款:" prop="invoicerecordBack">
                  <el-select v-model="RecordInvoice.invoicerecordBack" placeholder="未选"  style="width: 290px">
                    <el-option v-for="item in whetherbackOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="回款计划:" prop="invoicerecordPlanback">
                  <el-select v-model="RecordInvoice.invoicerecordPlanback" placeholder="未选"  style="width: 290px">
                    <el-option v-for="item in backplan" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="备注:" style="width: 830px">
                  <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容" v-model="RecordInvoice.invoicerecordNote"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12" :offset="6">
                <el-form-item>
                  <el-button type="primary" @click="addRecordInvoices()">保存</el-button>
                  <el-button @click="dialogFormVisible = false">取消</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <!--内层dialog-->
          <el-dialog width="30%" title="全部客户" :visible.sync="innerDialog" append-to-body>
            <!--选择客户-->
            <el-table :data="customerList" style="width: 100%">
              <el-table-column prop="customerId" label="客户编号" >
              </el-table-column>
              <el-table-column prop="customerName" label="客户名" >
              </el-table-column>
              <el-table-column label="请选择" >
                <template slot-scope="scope">
                  <el-button size="mini" @click="choiceCustomer(scope.row)" icon="el-icon-check" type="primary" circle style="margin-left: 10px"></el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-row style="margin-top:10px">
              <el-col :span="16">
                <el-pagination layout="prev, pager, next, jumper" :total="cusTotalSize" @current-change="cusChangePage"
                               :current-page.sync="cusCurrPage" :page-size="cusPageSize"></el-pagination>
              </el-col>
            </el-row>
          </el-dialog>
        </el-dialog>
    </div>
    <!--开票记录表格-->
    <el-table ref="multipleTable" :data="recordinvoiceList" tooltip-effect="dark" style="width: 100%"  @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" ></el-table-column>
      <el-table-column prop="invoicerecordId" label="ID" wsortable></el-table-column>
      <el-table-column prop="invoicerecordContent" label="开票内容" ></el-table-column>
      <el-table-column prop="invoicerecordType" label="票据类型" >
        <template slot-scope="scope">
          <span v-if="scope.row.invoicerecordType == 1">{{invoicetypeOptions[0].label}}</span>
          <span v-if="scope.row.invoicerecordType == 2">{{invoicetypeOptions[1].label}}</span>
          <span v-if="scope.row.invoicerecordType == 3">{{invoicetypeOptions[2].label}}</span>
          <span v-if="scope.row.invoicerecordType == 4">{{invoicetypeOptions[3].label}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="invoicerecordAmount" label="票据金额" >
       <!-- <template slot-scope="scope">
          <span style="color: #333333">
            <i class="el-icon-caret-right" @click="handleEdit(scope.row)" style="cursor: pointer"></i>
            <span>{{scope.row.invoice_amount}}</span>
          </span>
        </template>-->
      </el-table-column>
      <el-table-column prop="invoicerecordNo" label="发票号码" ></el-table-column>
      <el-table-column prop="invoicerecordDate" label="开票日期" ></el-table-column>
      <el-table-column prop="employeeByEmpId.empName" label="经手人" ></el-table-column>
      <el-table-column prop="invoicerecordBack" label="是否回款" >
        <template slot-scope="scope">
          <span v-if="scope.row.invoicerecordBack == 1">{{whetherbackOptions[0].label}}</span>
          <span v-if="scope.row.invoicerecordBack == 2">{{whetherbackOptions[1].label}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="contractByContractId.contractTheme" label="合同订单" >
        <template slot-scope="scope">
          <div style="color: #333333">
            <span>{{scope.row.contractByContractId.contractTheme}}</span>
            <el-tooltip class="item" effect="dark" content="打开详细页面" placement="bottom">
              <router-link :to="{path:'/ContractView',query: {contractId: scope.row.contractByContractId.contractId}}">
                  <span style="color: #333333">
                    <i class="el-icon-s-opportunity"></i>
                  </span>
              </router-link>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="customerByCustomerId.customerName" label="客户" >
        <template slot-scope="scope">
          <div style="color: #333333">
            <span>{{scope.row.customerByCustomerId.customerName}}</span>
            <el-tooltip class="item" effect="dark" content="打开详细页面" placement="bottom">
              <router-link :to="{path:'/CustomerView',query: {customerId: scope.row.customerByCustomerId.customerId}}">
                  <span style="color: #333333">
                    <i class="el-icon-s-opportunity"></i>
                  </span>
              </router-link>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="" label="操作" width="135px">
        <template slot-scope="scope">
         <!-- <router-link :to="'/'">
            <el-tooltip class="item" effect="dark" content="视图" placement="bottom">
              <el-button size="mini"
                         icon="el-icon-tickets" type="success" circle></el-button>
            </el-tooltip>
          </router-link>-->
          <el-button size="mini" @click="handleEdit(scope.row)"
                     icon="el-icon-edit" type="primary" circle style="margin-left: 10px"></el-button>
          <el-button size="mini" @click="handleDelete(scope.row)"
                     icon="el-icon-delete" type="danger" circle></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-row style="margin-top:10px">
      <!--<el-col :span="8">
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button style="padding: 12px 12px" icon="el-icon-delete" @click="handleDeleteMany" type="danger"></el-button>
        </el-tooltip>
      </el-col>
      <el-col :span="24">
        <el-pagination layout="prev, pager, next, jumper" :total="totalSize" @current-change="changePage"
                       :current-page.sync="currPage" :page-size="pageSize" style="margin-left:500px"></el-pagination>
      </el-col>-->
      <el-col :span="8">
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button style="padding: 12px 12px" icon="el-icon-delete" @click="handleDeleteMany" type="danger"></el-button>
        </el-tooltip>
      </el-col>
      <el-col :span="16">
        <el-pagination layout="sizes,prev,pager, next, jumper" :total="totalSize" @current-change="changePage"
                       :current-page.sync="currPage" :page-size="pageSize" :page-sizes="pageSizes" @size-change="changeSize"></el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>export default {
  data () {
    return {
      emp:{},
      recordinvoiceList:[],
      pageSize: 10, // 分页页大小
      pageSizes:[10,20,30],//页大小数组
      content: '',// input内容
      contractList:[],
      customerList: [], // 员工客户名称
      contactList: [], // 员工联系人集合
      pageSize: 5, // 分页页大小
      currPage: 1, // 当前页码，默认为1
      totalSize: 0, // 总记录数
      cusPageSize: 5, // 分页页大小
      cusCurrPage: 1, // 当前页码，默认为1
      cusTotalSize: 0, // 总记录数
      isCustomer: true, // 客户搜索显示
      innerDialog: false,// 内层dialog客户
      innerDialogEmp: false,// 内层dialog员工
      content: '',// input内容
      customerValue:'',// 模糊查询客户
      customerList2:[],// 模糊查询结果
      visible: false,// 模糊搜索结果
      //头部搜索框
      vagueOptions: [{
        value:  1,
        label: '开票日期'
      }, {
        value: 2,
        label: '发票号码'
      }, {
        value: 3,
        label: '对应客户'
      }],
      jhValue: '',
      vagueValue: 1,
      filterValue: {value:0,label: '全部数据',num:0},
      //导航搜索
      activeIndex: '2',
      /*下拉框条件查询*/
      filterOptions: [{
        label: '',
        options: [{
          value: 0,
          label: '全部数据',
          num:0
        }]
      }, {
        label: '票据类型',
        options: [{
          value: 1,
          label: '增值',
          num:1
        }, {
          value: 2,
          label: '普通国税',
          num:2
        }, {
          value: 3,
          label: '普通地税',
          num:3
        }, {
          value: 4,
          label: '收据',
          num:4
        }]
      }, {
        label: '回款',
        options: [{
          value: 5,
          label: '未回款',
          num:1
        }, {
          value: 6,
          label: '已回款',
          num:2
        }]
      }],
      allValue:'',
      dialogFormVisible: false,
      totalSize: 0,
      RecordInvoice: {
       invoicerecordId:0,
       invoicerecordContent:'',
       invoicerecordType:'',
       invoicerecordAmount:'0.0',
       invoicerecordNo:'',
       invoicerecordDate:'',
       invoicerecordPeriods:'',
       invoicerecordHandlers:'',
       invoicerecordBack:'',
       invoicerecordPlanback:'',
       invoicerecordNote:'',
       invoicerecordCustomerName:'',
       contractByContractId:'',
       employeeByEmpId:'',
       customerByCustomerId:''
      },
      //弹出框的期次
      periods: [{
        value: 1,
        label: '1'
      }, {
        value: 2,
        label: '2'
      }, {
        value: 3,
        label: '3'
      }, {
        value: 4,
        label: '4'
      }, {
        value: 5,
        label: '5'
      }, {
        value: 6,
        label: '6'
      }],
      //弹出框的票据类型
      invoicetypeOptions: [{
        value: 1,
        label: '增值'
      }, {
        value: 2,
        label: '普通国税'
      }, {
        value: 3,
        label: '普通地税'
      }, {
        value: 4,
        label: '收据'
      }],
      //状态
      whetherbackOptions: [{
        value: 1,
        label: '未回款'
      }, {
        value: 2,
        label: '已回款'
      }],
      backplan: [{
        value: 1,
        label: '未制定回款计划'
      }, {
        value: 2,
        label: '已制定回款计划'
      }, {
        value: 3,
        label: '已回款无须计划'
      }],
      whetherbackvalue:'',
      backplanvalue:'',
      periodvalue: '',
      invoicetypevalue: '',
      // 客户签约人(要从数据库里面查找)
      restaurants: [],
      state: '',
      timeout:  null,

      rules: {
        invoicerecordAmount: [
          { required: true, message: '必须填'},
          { type: 'number', message: '必须为数字'}
        ],
        invoicerecordPeriods:[
          { required: true, message: '必选', trigger: 'blur' }
        ],
        invoicerecordDate: [
          { required: true, message: '必选',trigger: 'blur'}
        ],
        invoicerecordNo:[
          { required: true, message: '必须填', trigger: 'blur' }
        ],
        'customerByCustomerId.customerName': [
          { required: true, message: '请选择客户', trigger: 'blur' }
        ],
        invoicerecordBack:[
          { required: true, message: '必选', trigger: 'blur' }
        ],
        invoicerecordPlanback:[
          { required: true, message: '必选', trigger: 'blur' }
        ],
        'contractByContractId':[
          { required: true, message: '请选择合同', trigger: 'blur' }
        ]},
      mulSelection: []
    }
  },
  methods: {
    // 查询当前员工
    loginEmp(){
      this.$axios.get('http://localhost:8088/emp')
        .then(v => {
          this.emp = v.data
        })
        .catch(function (v) {})
    },
    // 分页查询所有
    /*initData (currPage, pageSize) {
      this.$axios.get('http://localhost:8088/emp-invoicerecord-list', {
        params: {
          page: currPage,
          size: pageSize,
        }
      })
        .then(v => {
          this.recordinvoiceList = v.data.rows
          this.totalSize = v.data.total
          console.log(this.recordinvoiceList)
        })
        .catch(function (v) {})
    },*/
    initData (currPage, pageSize,filter,vague,content) {
      this.$axios.get('http://localhost:8088/emp-invoicerecord-list', {
        params: {
          page: currPage,
          size: pageSize,
          value:filter.value,
          num:filter.num,
          vague:vague,
          content:content
        }
      })
        .then(v => {
          this.recordinvoiceList = v.data.rows
          this.totalSize = v.data.total
        })
        .catch(function (v) {})
    },
    // 回款记录表格分页
    changePage (val) {
      // val就是当前页码
     /* this.initData(val, this.pageSize)*/
      this.initData(val,this.pageSize,this.filterValue,this.vagueValue,this.content)
  },
    //改变页大小
    changeSize(val){
      this.pageSize = val
      this.currPage = 1
      this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
    },
    //分类查询
    findInvoice(val){
      if(val.value == 0){
        this.initData(this.currPage, this.pageSize)
      }
      if (val.parentLabel == '票据类型'){
        this.$axios.get('http://localhost:8088/emp-invoicerecord-type-list', {
          params: {
            page: this.currPage,
            size: this.pageSize,
            invoicerecordType: val.value
          }
        })
          .then(v => {
            console.log(v.data.rows)
            this.recordinvoiceList = v.data.rows
            this.totalSize = v.data.total
          })
          .catch(function (v) {})
      }
      if (val.parentLabel == '回款'){
        this.$axios.get('http://localhost:8088/emp-invoicerecord-back-list', {
          params: {
            page: this.currPage,
            size: this.pageSize,
            invoicerecordBack: val.value
          }
        })
          .then(v => {
            console.log(v.data.rows)
            this.recordinvoiceList = v.data.rows
            this.totalSize = v.data.total
          })
          .catch(function (v) {})
      }
    },
    //查询回款日期或客户
    findClientOrDate(){
      if (this.content == ''){
        this.initData(this.currPage, this.pageSize)
      }
      if (this.jhValue == 1){
        this.$axios.get('http://localhost:8088/emp-invoicerecord-date-list', {
          params: {
            page: this.currPage,
            size: this.pageSize,
            invoicerecordDate: this.content
          }
        })
          .then(v => {
            console.log(v.data.rows)
            this.recordinvoiceList = v.data.rows
            this.totalSize = v.data.total
          })
          .catch(function (v) {})
      }else if(this.jhValue == 2){
        this.$axios.get('http://localhost:8088/emp-invoicerecord-number-list', {
          params: {
            page: this.currPage,
            size: this.pageSize,
            invoicerecordNo: this.content
          }
        })
          .then(v => {
            console.log(v.data.rows)
            this.recordinvoiceList = v.data.rows
            this.totalSize = v.data.total
          })
          .catch(function (v) {})
      }
      else if(this.jhValue == 3){
        this.$axios.get('http://localhost:8088/emp-invoicerecord-cusName-list', {
          params: {
            page: this.currPage,
            size: this.pageSize,
            customerName: this.content
          }
        })
          .then(v => {
            console.log(v.data.rows)
            this.recordinvoiceList = v.data.rows
            this.totalSize = v.data.total
          })
          .catch(function (v) {})
      }
    },
    //修改数据回显
    handleEdit(val) {
      this.dialogFormVisible = true
      this.RecordInvoice.invoicerecordId = val.invoicerecordId
      this.RecordInvoice.invoicerecordContent = val.invoicerecordContent
      this.RecordInvoice.invoicerecordType = val.invoicerecordType
      this.RecordInvoice.invoicerecordAmount = val.invoicerecordAmount
      this.RecordInvoice.invoicerecordNo = val.invoicerecordNo
      this.RecordInvoice.invoicerecordDate = val.invoicerecordDate
      this.RecordInvoice.invoicerecordPeriods = val.invoicerecordPeriods
      this.RecordInvoice.invoicerecordHandlers = val.invoicerecordHandlers
      this.RecordInvoice.invoicerecordBack = val.invoicerecordBack
      this.RecordInvoice.invoicerecordPlanback =val.invoicerecordPlanback
      this.RecordInvoice.invoicerecordNote  = val.invoicerecordNote
      this.RecordInvoice.invoicerecordCustomerName = val.invoicerecordCustomerName
      this.RecordInvoice.contractByContractId = val.contractByContractId
      this.RecordInvoice.employeeByEmpId = val.employeeByEmpId
      this.RecordInvoice.customerByCustomerId = val.customerByCustomerId
      this.choiceContact(val.customerByCustomerId.customerId) // 根据客户名查询联系人集合
      this.contractData(val.customerByCustomerId.customerId)
      this.isCustomer = false
    },
    //新增
    addRecordInvoices(){
      this.$refs.rei.validate((valid) => {
        if (valid) {
          this.$axios.post('http://localhost:8088/save-invoicerecord',
            {
              invoicerecordId:this.RecordInvoice.invoicerecordId,
              invoicerecordContent:this.RecordInvoice.invoicerecordContent,
              invoicerecordType:this.RecordInvoice.invoicerecordType,
              invoicerecordAmount:this.RecordInvoice.invoicerecordAmount,
              invoicerecordNo:this.RecordInvoice.invoicerecordNo,
              invoicerecordDate:this.RecordInvoice.invoicerecordDate,
              invoicerecordPeriods:this.RecordInvoice.invoicerecordPeriods,
              invoicerecordHandlers:this.RecordInvoice.invoicerecordHandlers,
              invoicerecordBack:this.RecordInvoice.invoicerecordBack,
              invoicerecordPlanback:this.RecordInvoice.invoicerecordPlanback,
              invoicerecordNote:this.RecordInvoice.invoicerecordNote,
              invoicerecordCustomerName:this.RecordInvoice.invoicerecordCustomerName,
              contractByContractId:this.RecordInvoice.contractByContractId,
              employeeByEmpId:this.RecordInvoice.employeeByEmpId,
              customerByCustomerId:this.RecordInvoice.customerByCustomerId
            })
            .then(v => {
              // 1、刷新数据
              this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
              // 2、关闭弹框
              this.dialogFormVisible = false
              this.$message({
                message: '已保存',
                type: 'success'
              });
            })
            .catch(function (v) {})
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 打开dialog事件
    openDialog () {
      this.RecordInvoice.employeeByEmpId = this.emp
    },
    // 关闭dialog事件
    closeDialog () {
      this.$refs.rei.resetFields()
      this.RecordInvoice = {
        invoicerecordId:0,
        invoicerecordContent:'',
        invoicerecordType:0,
        invoicerecordAmount:0.00,
        invoicerecordNo:'',
        invoicerecordDate:'',
        invoicerecordPeriods:0,
        invoicerecordHandlers:'',
        invoicerecordBack:0,
        invoicerecordPlanback:0,
        invoicerecordNote:'',
        invoicerecordCustomerName:'',
        customerByCustomerId:{},//客户
        contractByContractId:'',//合同订单
        employeeByEmpId: ''
      }
      this.recordinvoiceList = []
      this.isCustomer = true
      this.contactList = []
      this.contractList = []
    },
    // 打开内层dialog
    innerVisible (cusCurrPage,cusPageSize) {
      this.$axios.get('http://localhost:8088/emp-customer-list', {
        params: {
          page: cusCurrPage,
          size: cusPageSize,
        }
      })
        .then(v => {
          this.customerList = v.data.rows
          this.cusTotalSize = v.data.total
        })
        .catch(function (v) {})
      this.innerDialog = true
    },
    //查询客户分页
    cusChangePage (val) {
      // val就是当前页码
      this.innerVisible(val, this.cusPageSize)
    },
    //查询客户所有合同订单
    contractData(cusId) {
      this.$axios.get('http://localhost:8088/cus-contract-list-all', {
        params: {
          cusId: cusId
        }
      })
        .then(v => {
          this.contractList = v.data
        })
        .catch(function (v) {
        })
    },
    // 选择联系人(查询联系人)
    choiceContact(customerId){
      this.$axios.get('http://localhost:8088/contact-list', {
        params: {
          customerId : customerId
        }
      })
        .then(v => {
          this.contactList = v.data
        })
        .catch(function (v) {})
    },
    // 选择客户
    choiceCustomer(val){
      this.RecordInvoice.customerByCustomerId = val
      console.log(this.RecordInvoice.customerByCustomerId)
      this.choiceContact(val.customerId)
      this.contractData(val.customerId)
      this.innerDialog = false;
    },
    // 模糊查询客户
    findCustomer(){
      if (this.customerValue != ''){
        this.visible = true
        this.$axios.get('http://localhost:8088/emp-fuzzy-customer-list', {
          params: {
            customerName: this.customerValue
          }
        })
          .then(v => {
            this.customerList2 = v.data
          })
          .catch(function (v) {})
      }else {
        this.visible = false
      }
    },
    // 模糊选择客户
    choiceCustomer2(val){
      console.log(val)
      this.RecordInvoice.customerByCustomerId = val
      this.choiceContact(val.customerId)
      this.contractData(val.customerId)
      this.visible = false
    },
    // 失去焦点关闭模糊搜索框
    closeEmp(){
      this.visible = false
      this.customerValue = ''
    },
    // 选择员工
    choiceEmp(val){
      this.RecordInvoice.employeeByEmpId = val
      console.log(this.RecordInvoice.customerByCustomerId)
      this.$axios.get('http://localhost:8088/contact-list', {
        params: {
          customerId : val.customerId
        }
      })
        .then(v => {
          this.contactList = v.data
        })
        .catch(function (v) {})
      this.innerDialog = false;
    },
    // 删除提示
    handleDelete(val) {
      this.$confirm('此操作将永久删除该回款记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteRecordInvoice(val.invoicerecordId)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 批量删除提示
    handleDeleteMany () {
      this.$confirm('此操作将永久删除勾选开票记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteAll()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 获取批量删除对象集合
    handleSelectionChange (val) {
      this.mulSelection = val
    },
    // 删除axios
    deleteRecordInvoice(invoicerecordId) {
      this.$axios.post('http://localhost:8088/delete-invoicerecord', this.qs.stringify({invoicerecordId: invoicerecordId}))
        .then(v => {
          // 1、刷新数据
          this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
        })
        .catch(function (v) {
        })
    },
    // 删除所有
    deleteAll() {
      this.mulSelection.forEach(row => {
        this.deleteRecordInvoice(row.invoicerecordId)
      })
    },
    //客户签约人与我方签约人
    loadAll() {
      return [
        { "value": "陈浩南", "address": "crm工大小组" },
        { "value": "张三疯", "address": "crm工大小组" }
      ];
    },
    querySearchAsync(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 3000 * Math.random());
    },
    createStateFilter(queryString) {
      return (state) => {
        return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },
    handleSelect(item) {
      console.log(item);
    }
  },
  created:function(){
    this.loginEmp()
    this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
  },
  mounted() {
    this.restaurants = this.loadAll();
  }
}
</script>

<style>
  .font-14{
    font-size: 14px
  }
  .col-sm-6 {
    width: 50%;
    position: relative;
    min-height: 1px;

  }
  .text-muted {
    color: #98a6ad;
  }
  .font-13 {
    font-size: 13px !important;
  }
  .text-left{
    text-align: left;
    float: left;
  }
  .text-right {
    text-align: right;
    float: right;
  }
  .form-inline{
    position: relative;
    top: -15px;
    left: 100px;
  }
  .font-14-bold{
    color: #000000;
    font-weight: bold;
  }
</style>
